ValueFolderTemp='/sps/isc/rneveu/EtudeIRM/Nature/ResultsJournal/';
ValueFolderTemp2='/sps/isc/rneveu/EtudeIRM/Nature/ResultsEditor/';
load([ValueFolderTemp 'ResultsThirdLevelDistributionOutliers.mat']);
VecDistribution=VecResults;
load('/sps/isc/rneveu/EtudeIRM/Nature/EtudeNature.mat');
VecEditors1Temp(1,:)=[];
VecValueEditor=VecEditors1Temp;
load('/sps/isc/rneveu/EtudeIRM/Nature/DonneesNature.mat');
VecValueJournal=VecJournalTemp;
ValueCutoff=1.25;
VecResultsTemp1=[];
VecResultsTemp2=[];
VecResultsTemp11=[];
VecResultsTemp22=[];
VecValueYear=[0 1 2 3 4 5 10];
nMonthMax=12;
n1Temp=0;
VecFigure=[];
for n1=1:323
    ValueTemp=find(VecDistribution(:,1)==n1);
    if size(ValueTemp,1)==1
        if VecDistribution(ValueTemp,2)<=ValueCutoff
            ValueJournal=VecValueEditor{n1,11};
            n3=1;
            TestTemp=0;
            while n3<=size(VecValueJournal,1)&&TestTemp==0
                if strcmpi(ValueJournal,VecValueJournal{n3,1})==1
                    TestTemp=1;
                else
                    n3=n3+1;
                end
            end
            try
            load([ValueFolderTemp2 'FileAnalysisEditor' num2str(n1) '.mat']);
            load([ValueFolderTemp2 'FileAnalysisCharacteristicsEditor' num2str(n1) '.mat']);
            VecValueTemp2=zeros(2,size(VecValueYear,2)*nMonthMax*2);
            VecValueTemp22=[];
            for n2=1:33
                eval(['VecValueTemp=VecResultsEditorAuthors1FilteredJournal' num2str(n2) ';']);
%                 eval(['VecValueTemp=VecResultsEditorAffiliation1Journal' num2str(n2) ';']);
                VecValueTemp2=VecValueTemp2+VecValueTemp;
                if n2==n3
                    eval(['VecValueTemp=VecResultsEditorAuthors2FilteredJournal' num2str(n2) ';']);
%                     eval(['VecValueTemp=VecResultsEditorAffiliation2Journal' num2str(n2) ';']);
                    VecValueTemp22=VecValueTemp;
                end
            end
            VecValueTemp3=[];
            for n2=1:size(VecValueYear,2)*nMonthMax
                VecValueTemp3=[VecValueTemp3;VecValueTemp2(1,(n2-1)*2+1)-VecValueTemp2(1,(n2-1)*2+2) VecValueTemp2(1,(n2-1)*2+1)/VecValueTemp2(2,(n2-1)*2+1)-(VecValueTemp2(1,(n2-1)*2+2)/VecValueTemp2(2,(n2-1)*2+2))];
%                 VecResultsTemp11=[VecResultsTemp11;VecValueTemp2(1,(n2-1)*2+1) VecValueTemp2(2,(n2-1)*2+1) 1 VecResultsEditor(1,23) VecResultsEditor(1,3) VecResultsEditor(1,16) VecResultsEditor(1,27);VecValueTemp2(1,(n2-1)*2+2) VecValueTemp2(2,(n2-1)*2+2) 2 VecResultsEditor(1,23) VecResultsEditor(1,3) VecResultsEditor(1,16) VecResultsEditor(1,27)];
                VecResultsTemp11=[VecResultsTemp11;VecValueTemp2(1,(n2-1)*2+1) VecValueTemp2(1,(n2-1)*2+2) 1 VecResultsEditor(1,23) VecResultsEditor(1,3) VecResultsEditor(1,16) VecResultsEditor(1,27)];
            end
            VecValueTemp4=[VecResultsEditor(1,23) VecResultsEditor(1,3) VecResultsEditor(1,16) VecResultsEditor(1,27)];
            VecValueTemp3=[VecValueTemp3 repmat(VecValueTemp4,size(VecValueTemp3,1),1) n1*ones(size(VecValueTemp3,1),1)];
            VecResultsTemp1=[VecResultsTemp1;VecValueTemp3];
            VecValueTemp32=[];
            for n2=1:size(VecValueYear,2)*nMonthMax
                VecValueTemp32=[VecValueTemp32;VecValueTemp22(1,(n2-1)*2+1)-VecValueTemp22(1,(n2-1)*2+2) VecValueTemp22(1,(n2-1)*2+1)/VecValueTemp22(2,(n2-1)*2+1)-(VecValueTemp22(1,(n2-1)*2+2)/VecValueTemp22(2,(n2-1)*2+2))];
%                 VecResultsTemp22=[VecResultsTemp22;VecValueTemp22(1,(n2-1)*2+1) VecValueTemp22(2,(n2-1)*2+1) 1 VecResultsEditor(1,23) VecResultsEditor(1,3) VecResultsEditor(1,16) VecResultsEditor(1,27);VecValueTemp22(1,(n2-1)*2+2) VecValueTemp22(2,(n2-1)*2+2) 2 VecResultsEditor(1,23) VecResultsEditor(1,3) VecResultsEditor(1,16) VecResultsEditor(1,27)];
                VecResultsTemp22=[VecResultsTemp22;VecValueTemp22(1,(n2-1)*2+1) VecValueTemp22(1,(n2-1)*2+2) 1 VecResultsEditor(1,23) VecResultsEditor(1,3) VecResultsEditor(1,16) VecResultsEditor(1,27)];
            end
            VecValueTemp32=[VecValueTemp32 repmat(VecValueTemp4,size(VecValueTemp3,1),1) n1*ones(size(VecValueTemp32,1),1)];
            VecResultsTemp2=[VecResultsTemp2;VecValueTemp32];
            n2=2*nMonthMax+8;
            VecFigure=[VecFigure;VecValueTemp2(1,(n2-1)*2+2) VecValueTemp2(1,(n2-1)*2+1) VecValueTemp22(1,(n2-1)*2+2) VecValueTemp22(1,(n2-1)*2+1) VecResultsEditor(1,3) VecResultsEditor(1,27) n1 1];
            VecValueTemp2=zeros(2,size(VecValueYear,2)*nMonthMax*2);
            VecValueTemp22=[];
            for n2=1:33
                eval(['VecValueTemp=VecResultsEditorAffiliation1Journal' num2str(n2) ';']);
                VecValueTemp2=VecValueTemp2+VecValueTemp;
                if n2==n3
                    eval(['VecValueTemp=VecResultsEditorAffiliation2Journal' num2str(n2) ';']);
                    VecValueTemp22=VecValueTemp;
                end
            end
            n2=2*nMonthMax+8;
            VecFigure=[VecFigure;VecValueTemp2(1,(n2-1)*2+2) VecValueTemp2(1,(n2-1)*2+1) VecValueTemp22(1,(n2-1)*2+2) VecValueTemp22(1,(n2-1)*2+1) VecResultsEditor(1,3) VecResultsEditor(1,27) n1 2];
            n1Temp=n1Temp+1;
            end
        end
    end
end

save([ValueFolderTemp2 'FichierFigureCoAuthorsAffiliation.mat'],'VecFigure');

VecResults=[];
VecResults2=[];
VecResults1=[];
VecResults3=[];
for n1=1:size(VecValueYear,2)
    for n2=1:nMonthMax
        VecResultsTemp=[];
        for n3=1:n1Temp
            VecResultsTemp=[VecResultsTemp;VecResultsTemp1((n3-1)*size(VecValueYear,2)*nMonthMax+(n1-1)*nMonthMax+n2,:)];
        end
        ValueTemp=find(VecResultsTemp(:,1)<Inf&isnan(VecResultsTemp(:,1))==0);
        ValueTemp2=find(VecResultsTemp(:,2)<Inf&isnan(VecResultsTemp(:,2))==0);
        VecValueResultsTemp=VecResultsTemp;
        [ValueResults1Temp,ValueResults2]=signrank(VecResultsTemp(:,1));
        [ValueResults3Temp,ValueResults4]=signrank(VecResultsTemp(:,2));
        [ValueResults1,ValueResults2]=ttest(VecResultsTemp(ValueTemp,1));
        [ValueResults3,ValueResults4]=ttest(VecResultsTemp(ValueTemp2,2));
        [ValueResultsTemp,stats1]=robustfit(VecResultsTemp(ValueTemp,3),VecResultsTemp(ValueTemp,1));
        [ValueResultsTemp2,stats2]=robustfit(VecResultsTemp(ValueTemp,4),VecResultsTemp(ValueTemp,1));
        [ValueResultsTemp3,stats3]=robustfit(VecResultsTemp(ValueTemp,6),VecResultsTemp(ValueTemp,1));
        [ValueResults2Temp,stats4]=robustfit(VecResultsTemp(ValueTemp2,3),VecResultsTemp(ValueTemp2,2));
        [ValueResults2Temp2,stats5]=robustfit(VecResultsTemp(ValueTemp2,4),VecResultsTemp(ValueTemp2,2));
        [ValueResults2Temp3,stats6]=robustfit(VecResultsTemp(ValueTemp2,6),VecResultsTemp(ValueTemp2,2));
        VecResults=[VecResults;mean(VecResultsTemp(:,1)) sqrt(nanvar(VecResultsTemp(:,1)))/sqrt(size(VecResultsTemp,1)) ValueResults2 ValueResults1Temp mean(VecResultsTemp(ValueTemp2,2)*100) sqrt(nanvar(VecResultsTemp(ValueTemp2,2)*100))/sqrt(size(ValueTemp2,1)) ValueResults4 ValueResults3Temp n2 VecValueYear(1,n1) ValueResultsTemp' stats1.p' NaN ValueResultsTemp2' stats2.p' NaN ValueResultsTemp3' stats3.p' NaN ValueResults2Temp' stats4.p' NaN ValueResults2Temp2' stats5.p' NaN ValueResults2Temp3' stats6.p' NaN size(ValueTemp,1) size(ValueTemp2,1)];
        VecResultsTemp=[];
        for n3=1:n1Temp
            VecResultsTemp=[VecResultsTemp;VecResultsTemp2((n3-1)*size(VecValueYear,2)*nMonthMax+(n1-1)*nMonthMax+n2,:)];
        end
        ValueTemp=find(VecResultsTemp(:,1)<Inf&isnan(VecResultsTemp(:,1))==0);
        ValueTemp2=find(VecResultsTemp(:,2)<Inf&isnan(VecResultsTemp(:,2))==0);
        [ValueResults1Temp,ValueResults2]=signrank(VecResultsTemp(:,1));
        [ValueResults3Temp,ValueResults4]=signrank(VecResultsTemp(:,2));
        [ValueResults1,ValueResults2]=ttest(VecResultsTemp(ValueTemp,1));
        [ValueResults3,ValueResults4]=ttest(VecResultsTemp(ValueTemp2,2));
        [ValueResultsTemp,stats]=robustfit(VecResultsTemp(ValueTemp,3),VecResultsTemp(ValueTemp,1));
        [ValueResultsTemp2,stats]=robustfit(VecResultsTemp(ValueTemp,4),VecResultsTemp(ValueTemp,1));
        [ValueResultsTemp3,stats]=robustfit(VecResultsTemp(ValueTemp,6),VecResultsTemp(ValueTemp,1));
        [ValueResults2Temp,stats]=robustfit(VecResultsTemp(ValueTemp2,3),VecResultsTemp(ValueTemp2,2));
        [ValueResults2Temp2,stats]=robustfit(VecResultsTemp(ValueTemp2,4),VecResultsTemp(ValueTemp2,2));
        [ValueResults2Temp3,stats]=robustfit(VecResultsTemp(ValueTemp2,6),VecResultsTemp(ValueTemp2,2));
        VecResults2=[VecResults2;mean(VecResultsTemp(:,1)) sqrt(nanvar(VecResultsTemp(:,1)))/sqrt(size(VecResultsTemp,1)) ValueResults2 ValueResults1Temp mean(VecResultsTemp(ValueTemp2,2)) sqrt(nanvar(VecResultsTemp(ValueTemp2,2)))/sqrt(size(ValueTemp2,1)) ValueResults4 ValueResults3Temp n2 VecValueYear(1,n1) ValueResultsTemp' stats1.p' NaN ValueResultsTemp2' stats2.p' NaN ValueResultsTemp3' stats3.p' NaN ValueResults2Temp' stats4.p' NaN ValueResults2Temp2' stats5.p' NaN ValueResults2Temp3' stats6.p' NaN size(ValueTemp,1) size(ValueTemp2,1)];
        VecValueResultsTemp=VecResultsTemp(:,2)-VecValueResultsTemp(:,2);
        ValueTemp=find(VecValueResultsTemp(:,1)<Inf&isnan(VecValueResultsTemp(:,1))==0);
        [ValueResults1Temp,ValueResults2]=signrank(VecValueResultsTemp(ValueTemp,1));
        [ValueResults1,ValueResults2]=ttest(VecValueResultsTemp(ValueTemp,1));
        VecResults3=[VecResults3;nanmean(VecValueResultsTemp(ValueTemp,1)) sqrt(nanvar(VecValueResultsTemp(ValueTemp,1))) ValueResults1Temp ValueResults2 n2 VecValueYear(1,n1)];
        VecResultsTemp=[];
        for n3=1:n1Temp
%             VecResultsTemp=[VecResultsTemp;VecResultsTemp22(((n3-1)*size(VecValueYear,2)*nMonthMax+(n1-1)*nMonthMax+n2-1)*2+1:((n3-1)*size(VecValueYear,2)*nMonthMax+(n1-1)*nMonthMax+n2-1)*2+2,:)];
            VecResultsTemp=[VecResultsTemp;VecResultsTemp22((n3-1)*size(VecValueYear,2)*nMonthMax+(n1-1)*nMonthMax+n2,:)];
        end
%         ValueResults=anovan(VecResultsTemp(:,1),{VecResultsTemp(:,2) VecResultsTemp(:,3) VecResultsTemp(:,4)},'continuous',[1 3],'model',[1 0 0;0 1 0;0 0 1;1 1 0;1 0 1;0 1 1;1 1 1],'display','off');
        ValueResults=anovan(VecResultsTemp(:,1),{VecResultsTemp(:,2) VecResultsTemp(:,4)},'continuous',[1 2],'model',[1 0;0 1;1 1],'display','off');
        VecResults1=[VecResults1;ValueResults' n2 VecValueYear(1,n1)];
    end
end

ValueTemp=find(VecResults(:,10)==0);
VecResults(ValueTemp,10)=31*ones(size(ValueTemp,1),1);
VecValueTemp=VecResults(:,10)*12+VecResults(:,9);
[VecValueTemp,ValueTemp2]=sort(VecValueTemp);
VecResults=VecResults(ValueTemp2,:);
VecResults2=VecResults2(ValueTemp2,:);
figure
plot(VecValueTemp,VecResults2(:,5),'r-','LineWidth',4)
hold on
errorbar(VecValueTemp,VecResults2(:,5),VecResults2(:,6),'k+','LineWidth',1)
hold on
plot(VecValueTemp,VecResults(:,5),'-','LineWidth',4)
hold on
errorbar(VecValueTemp,VecResults(:,5),VecResults(:,6),'k+','LineWidth',1)



        
